<?

if($_POST["selbox"] != ''){

	if($check_me_authed == "OK"){

		$today_date 			= date("d-m-Y");

		$srcDbHdr			  = "STK_BAL_HDR";
    $srcDbHdrLog     = "LOG_STK_BAL_HDR";
    $srcDbDtl        = "STK_BAL_DTL";

    $UID     = unserialize($_SESSION["serUID"]);
    $userId  = $UID->getUID();

		$Db = new oracleDb;
    $Db->init($_SESSION["ORCL"],
               $_SESSION["OPASS"],
               $_SESSION["SID"],
               _NO_COMMENT);

    if ($Db->connect()) {


			if(sizeof($_POST["selbox"]) == 0){

				$Misc->usrDieJs("Error nothing to be delete");
			}else{

				foreach($_POST["selbox"] as $delThisJobId){

          /**
      		* Fetch global header
      		* And check the status if it is valid
      		* where STATUS = _NOT_ACTIVE
      		*
      		*/
      		$CFetchers->fetchLstDataHeader($Db,
                                         $delThisJobId,
                                         $srcDbHdr,
                                         $nHeader,
                                         $lstHeader);

          if($lstHeader["STATUS"][0] == _NOT_ACTIVE){

            /**
          	* Delete the previous entry
          	*
          	*/
          	$CHandlers->dbEntDelete($Db,
                      	            $delThisJobId,
                      	            $srcDbHdr);

            $CHandlers->dbEntDelete($Db,
                      	            $delThisJobId,
                      	            $srcDbDtl);

            /**
            * Insert Log
            *
            */
            $CHandlers->insToDbLog($Db,
                                   $today_date,
                                   $delThisJobId,
                                   $userId,
                                   $_SERVER["REMOTE_ADDR"],
                                   _DELETE_MODE,
                                   $srcDbHdrLog);

          }else{

            $Misc->usrDieJs("Error: Tx is ACTIVE/APPROVED/CANCELED");
          }

			  }

  			$Db->commit();

  			if($Db->getStatus() == true){

      	  $Misc->usrMsg("Delete Complete");
      	}else{

      	  $Misc->usrMsg("Delete Process Interupted");
      	}

      	$Db->dc();

  			//jumpTo(2,"../".$_SESSION["source_caller"]);
      }
		}else{

			$Misc->usrDieJs(_DB_CONN_ERROR);
		}
	}else{

		$Misc->usrDieJs("Error: Connection to oracle Failed");
	}
}else{

  $Misc->usrDieJs("Error: No Selection");
}
?> 